package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.dto.req.auditmanager.PurchaseOrderAuditReqDTO;
import com.yixin.hospital.service.AuditFlowDetailService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/audit-manager")
@Api(value = "审批管理", tags = "审批管理")
public class AuditManagerController {
    @Resource
    private AuditFlowDetailService auditFlowDetailService;

    @PostMapping("/audit")
    @ApiOperation(value = "审批")
    @Transactional
    public ApiResult<?> audit(@Valid @RequestBody PurchaseOrderAuditReqDTO drugPutBillAuditReqDTO, HttpServletRequest request) {
        Long userId = JwtUtil.getUserId(request.getHeader(Constant.AUTHORIZATION));
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return auditFlowDetailService.audit(drugPutBillAuditReqDTO, userId, userName);
    }

}
